
/*
vgMachine.cc
This file is part of opengl-vrml-assembly.
Copyright (C) Rafal Pielech, rafal.pielech@gmail.com

opengl-vrml-assembly is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

opengl-vrml-assembly is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with opengl-vrml-assembly.  If not, see <http://www.gnu.org/licenses/>.
*/

#include <vgMachine.h>
#include <QtXml/QDomDocument>
#include <QtXml/QDomElement>
#include <QtXml/QDomNamedNodeMap>
#include <QtXml/QDomNode>
#include <QtCore/QFile>
#include <QtCore/QString>

vgMachine::vgMachine(void)
{
  // Assign initial name
  name.clear();
  // Zero transformation matrix
  memset(&transfMatrix, 0, VG_TRANSF_MATRIX_SIZE);
}

bool vgMachine::vgBuild(const string& xmlFile)
{
  QFile xmlData(QString::fromStdString(xmlFile));
  QDomDocument machineCfg;

  QString errorStr;
  int errorLine;
  int errorColumn;

  if(machineCfg.setContent(&xmlData, &errorStr, &errorLine, &errorColumn))
  {
    // Success - XML is read in.
    QDomElement cfgRoot = machineCfg.documentElement();
    QDomNamedNodeMap cfgRootAttr = machineCfg.attributes();
    QDomNode machineName = cfgRootAttr.namedItem(QString::fromStdString(string("name")));
    // Assign machine name
    name = machineName.nodeValue().toStdString();
  }
}

const string& vgMachine::vgGetName(void) const
{
  return name;
}

vgMachine::~vgMachine(void)
{
}
